home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Grabber ƒ / sources ƒ / grabber_cdev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-15  |  3.1 KB  |  198 lines  |  [TEXT/KAHL]

  1.  
  2. /*
  3.  *  grabber cdev
  4.  *
  5.  *  Copyright © 1990 Michael Kahl.
  6.  *
  7.  */
  8.  
  9. #include <VRetraceMgr.h>
  10.  
  11. #include "grabber_cdev.h"
  12.  
  13. static void *FindVBL(void);
  14.  
  15.  
  16. /*  item numbers  */
  17. enum {
  18.     iTitle = 1,
  19.     iEnabled,
  20.     iMomentum,
  21.     iFriction,
  22.     iControl,
  23.     iShift,
  24.     iCommand,
  25.     iOption,
  26.     iCapsLock
  27. };
  28.  
  29.  
  30. /*
  31.  *  New - create the cdev object
  32.  *
  33.  */
  34.  
  35. cdev *
  36. New()
  37. {
  38.     return(new(grabber_cdev));
  39. }
  40.  
  41.  
  42. /*
  43.  *  Runnable - should the cdev appear in the Control Panel?
  44.  *
  45.  *  This implements the "macDev" message.  If the INIT was not installed,
  46.  *  we don't want the cdev to show up in the Control Panel.
  47.  *
  48.  */
  49.  
  50. Boolean
  51. Runnable()
  52. {
  53.     return(FindVBL() != 0);
  54. }
  55.  
  56.  
  57. /*
  58.  *  grabber_cdev::Init
  59.  *
  60.  */
  61.  
  62. void
  63. grabber_cdev::Init()
  64. {
  65.     inherited::Init();
  66.     
  67.         /*  get pointer to options record  */
  68.  
  69.     opt = FindVBL();
  70.     
  71.         /*  set up checkboxes from options  */
  72.  
  73.     if (opt->enabled)
  74.         SetCtlValue(GetCheckBox(iEnabled), 1);
  75.     if (opt->momentum)
  76.         SetCtlValue(GetCheckBox(iMomentum), 1);
  77.     if (opt->friction)
  78.         SetCtlValue(GetCheckBox(iFriction), 1);
  79.     if (opt->control)
  80.         SetCtlValue(GetCheckBox(iControl), 1);
  81.     if (opt->shift)
  82.         SetCtlValue(GetCheckBox(iShift), 1);
  83.     if (opt->command)
  84.         SetCtlValue(GetCheckBox(iCommand), 1);
  85.     if (opt->option)
  86.         SetCtlValue(GetCheckBox(iOption), 1);
  87.     if (opt->capsLock)
  88.         SetCtlValue(GetCheckBox(iCapsLock), 1);
  89. }
  90.  
  91.  
  92. /*
  93.  *  grabber_cdev::ItemHit
  94.  *
  95.  */
  96.  
  97. void
  98. grabber_cdev::ItemHit(item)
  99. int item;
  100. {
  101.     ControlHandle check = GetCheckBox(item);
  102.     int value = 1 - GetCtlValue(check);
  103.     Handle r;
  104.  
  105.     SetCtlValue(check, value);
  106.     
  107.         /*  update options record  */
  108.  
  109.     switch (item) {
  110.         case iEnabled:
  111.             opt->enabled = value;
  112.             break;
  113.         case iMomentum:
  114.             opt->momentum = value;
  115.             break;
  116.         case iFriction:
  117.             opt->friction = value;
  118.             break;
  119.         case iControl:
  120.             opt->control = value;
  121.             break;
  122.         case iShift:
  123.             opt->shift = value;
  124.             break;
  125.         case iCommand:
  126.             opt->command = value;
  127.             break;
  128.         case iOption:
  129.             opt->option = value;
  130.             break;
  131.         case iCapsLock:
  132.             opt->capsLock = value;
  133.             break;
  134.     }
  135.     
  136.         /*  update options resource  */
  137.  
  138.     if (r = Get1Resource('cnfg', 0)) {
  139.         * (struct opt *) *r = *opt;
  140.         ChangedResource(r);
  141.     }
  142. }
  143.  
  144.  
  145. /*
  146.  *  grabber_cdev::GetCheckBox
  147.  *
  148.  */
  149.  
  150. ControlHandle
  151. grabber_cdev::GetCheckBox(int item)
  152. {
  153.     int type;
  154.     ControlHandle check;
  155.     Rect box;
  156.  
  157.     GetDItem(dp, lastItem + item, &type, &check, &box);
  158.     return(check);
  159. }
  160.  
  161.  
  162. /*
  163.  *  FindVBL - get pointer to options record
  164.  *
  165.  *  The INIT has left a trail of bread crumbs so we can find it in memory.
  166.  *  We search the vertical retrace queue looking for its signature, which
  167.  *  looks like:
  168.  *
  169.  *        dc.l    ??            ;  ==> options record
  170.  *        dc.l    'grab'        ;  signature
  171.  *        dc.l    'INIT'        ;  signature
  172.  *        ;  VBL code starts here
  173.  *
  174.  *  (The VBL task itself doesn't do anything, other than reset its count whenever
  175.  *  it runs down so that it will remain in the queue.)
  176.  *
  177.  */
  178.  
  179. static void *
  180. FindVBL(void)
  181. {
  182.     register VBLQElPtr p;
  183.     register void *q;
  184.     
  185.     for (p = (VBLQElPtr) VBLQueue.qHead; p; p = (VBLQElPtr) p->qLink) {
  186.         q = p->vblAddr;
  187.         asm {
  188.             cmpi.l    #'INIT',-(q)
  189.             bne        @1
  190.             cmpi.l    #'grab',-(q)
  191.             bne        @1
  192.             move.l    -(q),d0
  193.             return
  194. @1        }
  195.     }
  196.     return(0);        /*  not found - INIT must not have run  */
  197. }
  198.